package com.grj.parkingsystem.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.grj.parkingsystem.common.Result;
import com.grj.parkingsystem.entity.ParkingLot;
import com.grj.parkingsystem.entity.ParkingSpace;
import com.grj.parkingsystem.service.ParkingLotService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/parkingLot")
@Api(tags = "3. 停车场管理")
public class ParkingLotController {

    @Autowired
    private ParkingLotService parkingLotService;

    @GetMapping("/nearby")
    @ApiOperation(value = "获取附近停车场", notes = "根据经纬度获取附近的停车场列表")
    @ApiOperationSupport(order = 1)
    public Result<?> getNearbyParkings(@RequestParam double latitude,
                                     @RequestParam double longitude,
                                     @RequestParam(required = false, defaultValue = "5.0") double radius) {
        List<ParkingLot> parkingLots = parkingLotService.getNearbyParkings(latitude, longitude, radius);
        return Result.success(parkingLots);
    }

    @GetMapping("/detail/{id}")
    @ApiOperation(value = "获取停车场详情", notes = "获取指定ID的停车场详细信息")
    @ApiOperationSupport(order = 2)
    public Result<?> getParkingLotDetail(@PathVariable Long id) {
        ParkingLot parkingLot = parkingLotService.getById(id);
        return Result.success(parkingLot);
    }

    @GetMapping("/spaces/{parkingLotId}")
    @ApiOperation(value = "获取停车场车位信息", notes = "获取指定停车场的车位信息，包括可用车位")
    @ApiOperationSupport(order = 3)
    public Result<?> getParkingSpaces(@PathVariable Long parkingLotId) {
        List<ParkingSpace> spaces = parkingLotService.getParkingSpaces(parkingLotId);
        return Result.success(spaces);
    }
}